package NC55_最长公共前缀;

import java.util.*;


public class Solution {
    /**
     *
     * @param strs string字符串一维数组
     * @return string字符串
     */
    public String longestCommonPrefix (String[] strs) {
        // write code here
        if (strs.length == 0 || strs == null){
            return "";
        }

        int rows = strs.length;
        int cols = strs[0].length();

        for (int i = 0; i < cols; i++){
            char firstChar = strs[0].charAt(i);
            for (int j = 1; j < rows; j++){
                if (strs[j].length() == i || strs[j].charAt(i) != firstChar){
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0];
    }
}